import config from '@/config';
import { ENV } from '@/constants/common';
class XltData {
  constructor() {
    this.xltdata = window['xxx'];
    this.server_url = config.xltdataUrl;
  }
  // 初始化
  init(callback) {
    this.xltdata.init({
      server_url: this.server_url,
      cross_subdomain: false,
      heatmap: { scroll_notice_map: 'not_collect' },
      is_track_single_page: true,
      use_client_time: true,
      send_type: 'beacon',
      show_log: config.env.toUpperCase() !== ENV.PROD || process.env.NODE_ENV === 'development'
    });

    this.xltdata.quick('isReady', function () {
      callback && callback();
    });
  }

  // 设置公共属性
  setCommonProperty(property = {}) {
    this.xltdata.registerPage(property);
  }

  // 自动收集
  quick(name = 'autoTrack') {
    return this.xltdata.quick(name);
  }
  // 发送事件
  track(eventName, data = {}, callback = () => { }) {
    this.xltdata.track(eventName, data, callback);
  }

  login(loginId) {
    this.xltdata.login(loginId);
  }
}

export default new XltData();
